import os
import allure
import page
from page.page_login import PageLogin
from page.page_shop import PageShop
from tool.get_driver import GetDriver
from tool.get_log import GetLogger

log = GetLogger.get_log()
module_name = str(os.path.basename(__file__)).split('.')[0]

@allure.epic("我的页面")
@allure.feature("积分商城测试用例")
class TestShop:
    @classmethod
    def setup_class(cls):
        cls.driver = GetDriver.get_app_driver()
        cls.login = PageLogin(cls.driver)
        cls.shop = PageShop(cls.driver)
        try:
            cls.login.base_click_element(page.approve)
        except:
            pass
        try:
            cls.login.base_click_element(page.skip_user_desc)
        except:
            pass
        cls.login.pagelogin(os.environ['SHOP_USERNAME'], password='123456')
        cls.login.base_click_element(page.wd_tab)

    @classmethod
    def teardown_class(cls):
        GetDriver.quit_app_driver()

    @allure.story("积分商城跳转用例")
    def test01_shop_enter(self):
        self.shop.pageshop_click_shop()
        log.info("正在进行断言")
        try:
            assert self.shop.pageshop_get_page_title() == '积分商城'
            log.info('断言成功')
            self.shop.base_get_screenshot_as_file(module_name, '断言成功截图')
        except Exception:
            self.shop.base_get_screenshot_as_file(module_name, '跳转积分商城失败')
            log.error('断言失败')
            raise
        finally:
            self.shop.pageshop_return_to_wdpage_keycode()

